<!DOCTYPE html>

<html>
<head>
  <title>map.coffee</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" media="all" href="public/stylesheets/normalize.css" />
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div class="container">
    <div class="page">

      <div class="header">
        
          <h1>map.coffee</h1>
        

        
          <div class="toc">
            <h3>Table of Contents</h3>
            <ol>
              
                
                <li>
                  <a class="source" href="admin.html">
                    admin.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.auditData.html">
                    api.auditData.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.auditEvent.html">
                    api.auditEvent.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.html">
                    api.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.entity.html">
                    api.entity.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.map.html">
                    api.map.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.server.html">
                    api.server.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.variable.html">
                    api.variable.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="api.view.html">
                    api.view.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="app.instance.html">
                    app.instance.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="appjs.html">
                    appjs.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="data.html">
                    data.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="dataUtil.html">
                    dataUtil.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="manager.html">
                    manager.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="messages.html">
                    messages.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditData.html">
                    auditData.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditEvent.html">
                    auditEvent.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="base.html">
                    base.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entityDefinition.html">
                    entityDefinition.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entityObject.html">
                    entityObject.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="eventAction.html">
                    eventAction.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="eventRule.html">
                    eventRule.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="link.html">
                    link.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="map.html">
                    map.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shape.html">
                    shape.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="user.html">
                    user.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="userSettings.html">
                    userSettings.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="variable.html">
                    variable.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="adminRoutes.html">
                    adminRoutes.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="appRoutes.html">
                    appRoutes.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="settings.html">
                    settings.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="sockets.html">
                    sockets.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="tutorial.html">
                    tutorial.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="vectors.html">
                    vectors.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="statusTabView.html">
                    statusTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="toolsTabView.html">
                    toolsTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="usersTabView.html">
                    usersTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="adminView.html">
                    adminView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="alertView.html">
                    alertView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditDataManagerView.html">
                    auditDataManagerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="auditEventManagerView.html">
                    auditEventManagerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="baseView.html">
                    baseView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="createMapView.html">
                    createMapView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entityManagerView.html">
                    entityManagerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="footerView.html">
                    footerView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="helpView.html">
                    helpView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="entitiesTabView.html">
                    entitiesTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="inspectorTabView.html">
                    inspectorTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="mapTabView.html">
                    mapTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapeTabView.html">
                    shapeTabView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="controlsView.html">
                    controlsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="labelEditView.html">
                    labelEditView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="linkCreatorView.html">
                    linkCreatorView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="linkLabelsView.html">
                    linkLabelsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="linkView.html">
                    linkView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapeLabelsView.html">
                    shapeLabelsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapeView.html">
                    shapeView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="shapesMoverView.html">
                    shapesMoverView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="mapView.html">
                    mapView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="menuView.html">
                    menuView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="overlayView.html">
                    overlayView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="scriptEditorView.html">
                    scriptEditorView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="settingsView.html">
                    settingsView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="startView.html">
                    startView.coffee
                  </a>
                </li>
              
                
                <li>
                  <a class="source" href="variableManagerView.html">
                    variableManagerView.coffee
                  </a>
                </li>
              
            </ol>
          </div>
        
      </div>

      
        
        <h2 id="mapfilter-model">MAPFILTER MODEL</h2>

        
      
        
        <p>Represents a map containing a collection of <a href="shape.html">Shapes</a>
and <a href="link.html">Links</a>, and specific sizes and colours.</p>

        
          <div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">SystemApp</span>.<span class="title">Map</span> <span class="keyword">extends</span> <span class="title">SystemApp</span>.<span class="title">BaseModel</span></span>
    <span class="attribute">typeName</span>: <span class="string">"Map"</span>
    <span class="attribute">defaults</span>:
        <span class="attribute">createdByUserId</span>: <span class="literal">null</span>
        <span class="attribute">background</span>: SystemApp.Settings.map.background
        <span class="attribute">paperSizeX</span>: SystemApp.Settings.map.paperSizeX
        <span class="attribute">paperSizeY</span>: SystemApp.Settings.map.paperSizeY
        <span class="attribute">gridSizeX</span>: SystemApp.Settings.map.gridSizeX
        <span class="attribute">gridSizeY</span>: SystemApp.Settings.map.gridSizeY
        <span class="attribute">thumbnailDate</span>: <span class="keyword">new</span> Date(<span class="number">2000</span>, <span class="number">1</span>, <span class="number">1</span>)
        <span class="attribute">silent</span>: <span class="literal">false</span>
        <span class="attribute">isReadOnly</span>: <span class="literal">false</span>

    <span class="attribute">relations</span>:
        <span class="attribute">links</span>: SystemApp.LinkCollection
        <span class="attribute">shapes</span>: SystemApp.ShapeCollection</pre></div>
        
      
        
        <h2 id="properties">PROPERTIES</h2>

        
      
        
        <p>Helper to get / set the ID of user who created the map.</p>

        
          <div class='highlight'><pre>    <span class="attribute">createdByUserId</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"createdByUserId"</span>, value
        <span class="property">@get</span> <span class="string">"createdByUserId"</span></pre></div>
        
      
        
        <p>Helper to get / set the map name.</p>

        
          <div class='highlight'><pre>    <span class="attribute">name</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"name"</span>, value
            console.warn <span class="string">"new name"</span>, value
        <span class="property">@get</span> <span class="string">"name"</span></pre></div>
        
      
        
        <p>Helper to get / set the map creation date.</p>

        
          <div class='highlight'><pre>    <span class="attribute">dateCreated</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"dateCreated"</span>, value
        <span class="property">@get</span> <span class="string">"dateCreated"</span></pre></div>
        
      
        
        <p>Helper to get / set the map background: a color or image url.</p>

        
          <div class='highlight'><pre>    <span class="attribute">background</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"background"</span>, value
        <span class="property">@get</span> <span class="string">"background"</span></pre></div>
        
      
        
        <p>Helper to get / set the map paper X size, in pixels.</p>

        
          <div class='highlight'><pre>    <span class="attribute">paperSizeX</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"paperSizeX"</span>, value
        <span class="property">@get</span> <span class="string">"paperSizeX"</span></pre></div>
        
      
        
        <p>Helper to get / set the map paper Y size, in pixels.</p>

        
          <div class='highlight'><pre>    <span class="attribute">paperSizeY</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"paperSizeY"</span>, value
        <span class="property">@get</span> <span class="string">"paperSizeY"</span></pre></div>
        
      
        
        <p>Helper to get / set the map grid X size, in pixels. This represents the distance between vertical lines.</p>

        
          <div class='highlight'><pre>    <span class="attribute">gridSizeX</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"gridSizeX"</span>, value
        <span class="property">@get</span> <span class="string">"gridSizeX"</span></pre></div>
        
      
        
        <p>Helper to get / set the map grid Y size, in pixels. This represents the distance between horizontal lines.</p>

        
          <div class='highlight'><pre>    <span class="attribute">gridSizeY</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"gridSizeY"</span>, value
        <span class="property">@get</span> <span class="string">"gridSizeY"</span></pre></div>
        
      
        
        <p>Helper to get / set the map init script.</p>

        
          <div class='highlight'><pre>    <span class="attribute">initScript</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"initScript"</span>, value
        <span class="property">@get</span> <span class="string">"initScript"</span></pre></div>
        
      
        
        <p>Helper to get / set map isLocal flag.</p>

        
          <div class='highlight'><pre>    <span class="attribute">isLocal</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"isLocal"</span>, value
        <span class="property">@get</span> <span class="string">"isLocal"</span></pre></div>
        
      
        
        <p>Helper to get / set map read only flag.</p>

        
          <div class='highlight'><pre>    <span class="attribute">isReadOnly</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"isReadOnly"</span>, value
        <span class="property">@get</span> <span class="string">"isReadOnly"</span></pre></div>
        
      
        
        <p>Helper to get / set the map silent mode.</p>

        
          <div class='highlight'><pre>    <span class="attribute">silent</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"silent"</span>, value
        <span class="property">@get</span> <span class="string">"silent"</span></pre></div>
        
      
        
        <p>Helper to get / set the shapes and their positions on the map. This must set as a <a href="shape.html">ShapeCollection</a>.</p>

        
          <div class='highlight'><pre>    <span class="attribute">shapes</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            value = <span class="keyword">new</span> SystemApp.ShapeCollection value <span class="keyword">if</span> <span class="keyword">not</span> value.typeName?
            <span class="property">@set</span> <span class="string">"shapes"</span>, value
        <span class="property">@get</span> <span class="string">"shapes"</span></pre></div>
        
      
        
        <p>Helper to get / set the links between shapes on the map. This must set as a <a href="link.html">LinkCollection</a>.</p>

        
          <div class='highlight'><pre>    <span class="attribute">links</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            value = <span class="keyword">new</span> SystemApp.LinkCollection value <span class="keyword">if</span> <span class="keyword">not</span> value.typeName?
            <span class="property">@set</span> <span class="string">"links"</span>, value
        <span class="property">@get</span> <span class="string">"links"</span></pre></div>
        
      
        
        <p>Helper to get / set the last date when the map&#39;s thumbnail was generated.</p>

        
          <div class='highlight'><pre>    <span class="attribute">thumbnailDate</span>: <span class="function"><span class="params">(value)</span> =&gt;</span>
        <span class="keyword">if</span> value?
            <span class="property">@set</span> <span class="string">"thumbnailDate"</span>, value
        <span class="property">@get</span> <span class="string">"thumbnailDate"</span></pre></div>
        
      
        
        <p>Helper to get the map&#39;s URL key based on its name: replace all spaces and special characters.</p>

        
          <div class='highlight'><pre>    <span class="attribute">urlKey</span>:<span class="function"> =&gt;</span>
        <span class="keyword">if</span> <span class="property">@isLocal</span>()
            <span class="keyword">return</span> SystemApp.Settings.map.localMapId
        <span class="keyword">return</span> SystemApp.DataUtil.getUrlKey <span class="property">@name</span>()</pre></div>
        
      
        
        <h2 id="local-maps">LOCAL MAPS</h2>

        
      
        
        <p>Helper to get data from local storage and set map as local.</p>

        
          <div class='highlight'><pre>    <span class="attribute">initLocalMap</span>:<span class="function"> =&gt;</span>
        <span class="property">@id</span> = SystemApp.Settings.map.localMapId
        <span class="property">@set</span> <span class="string">"id"</span>, SystemApp.Settings.map.localMapId
        <span class="property">@set</span> <span class="string">"isLocal"</span>, <span class="literal">true</span>
        <span class="property">@fetch</span>()

        currentName = <span class="property">@name</span>()

        <span class="keyword">if</span> <span class="keyword">not</span> currentName? <span class="keyword">or</span> currentName <span class="keyword">is</span> <span class="string">""</span>
            <span class="property">@name</span> SystemApp.Messages.localMapName

        <span class="keyword">return</span> <span class="property">@name</span>()</pre></div>
        
      
        
        <h2 id="validate">VALIDATE</h2>

        
      
        
        <p>All validation rules should be put inside this method.</p>

        
          <div class='highlight'><pre>    <span class="attribute">validate</span>: <span class="function"><span class="params">(attrs)</span> =&gt;</span></pre></div>
        
      
        
        <p>Name must be set.</p>

        
          <div class='highlight'><pre>        <span class="keyword">if</span> <span class="keyword">not</span> attrs.name? <span class="keyword">or</span> attrs.name <span class="keyword">is</span> <span class="string">""</span>
            <span class="keyword">return</span> SystemApp.Messages.valNameIsRequired</pre></div>
        
      
        
        <p>Grid size X can&#39;t be too low.</p>

        
          <div class='highlight'><pre>        <span class="keyword">if</span> <span class="keyword">not</span> attrs.gridSizeX? <span class="keyword">or</span> attrs.gridSizeX &lt; SystemApp.Settings.map.minGridSize
            <span class="keyword">return</span> SystemApp.Messages.valGridSizeTooSmall</pre></div>
        
      
        
        <p>Grid size Y can&#39;t be too low.</p>

        
          <div class='highlight'><pre>        <span class="keyword">if</span> <span class="keyword">not</span> attrs.gridSizeY? <span class="keyword">or</span> attrs.gridSizeY &lt; SystemApp.Settings.map.minGridSize
            <span class="keyword">return</span> SystemApp.Messages.valGridSizeTooSmall</pre></div>
        
      
        
        <p>Paper size X can&#39;t be too low.</p>

        
          <div class='highlight'><pre>        <span class="keyword">if</span> <span class="keyword">not</span> attrs.paperSizeX? <span class="keyword">or</span> attrs.paperSizeX &lt; SystemApp.Settings.map.minPaperSize
            <span class="keyword">return</span> SystemApp.Messages.valPaperSizeTooSmall</pre></div>
        
      
        
        <p>Paper size Y can&#39;t be too low.</p>

        
          <div class='highlight'><pre>        <span class="keyword">if</span> <span class="keyword">not</span> attrs.paperSizeY? <span class="keyword">or</span> attrs.paperSizeY &lt; SystemApp.Settings.map.minPaperSize
            <span class="keyword">return</span> SystemApp.Messages.valPaperSizeTooSmall</pre></div>
        
      
        
        <h2 id="shape-and-link-methods">SHAPE AND LINK METHODS</h2>

        
      
        
        <p>Removes a <a href="shape.html">Shape</a> from the <code>shapes</code> collection.</p>

        
          <div class='highlight'><pre>    <span class="attribute">removeShape</span>: <span class="function"><span class="params">(shape)</span> =&gt;</span>
        <span class="property">@shapes</span>().remove <span class="property">@shapes</span>().get shape.id
        <span class="property">@removeShapeLinks</span> shape

        <span class="property">@save</span>()</pre></div>
        
      
        
        <p>Removes a all links related to the specified <a href="shape.html">Shape</a> from the <code>links</code> collection.</p>

        
          <div class='highlight'><pre>    <span class="attribute">removeShapeLinks</span>: <span class="function"><span class="params">(shape)</span> =&gt;</span>
        _.each <span class="property">@links</span>, <span class="function"><span class="params">(link)</span> =&gt;</span>
            <span class="keyword">if</span> link.sourceId() <span class="keyword">is</span> shape.id <span class="keyword">or</span> link.targetId() <span class="keyword">is</span> shape.id
                <span class="property">@removeLink</span> link</pre></div>
        
      
        
        <p>Remove a <a href="link.html">Link</a> from the <code>links</code> collection.</p>

        
          <div class='highlight'><pre>    <span class="attribute">removeLink</span>: <span class="function"><span class="params">(link)</span> =&gt;</span>
        <span class="property">@links</span>().remove <span class="property">@links</span>().get link.id
        <span class="property">@save</span>()</pre></div>
        
      
        
        <p>Clear all links which have invalid <code>sourceId</code> or <code>targetId</code>.</p>

        
          <div class='highlight'><pre>    <span class="attribute">clearInvalidLinks</span>:<span class="function"> =&gt;</span>
        removeLinks = []
        _.each <span class="property">@links</span><span class="function"><span class="params">()</span>.<span class="title">models</span>, <span class="params">(link)</span> =&gt;</span>
            <span class="keyword">if</span> <span class="property">@shapes</span>().where({<span class="attribute">id</span>: link.sourceId()}).length &lt; <span class="number">1</span> <span class="keyword">or</span> <span class="property">@shapes</span>().where({<span class="attribute">id</span>: link.targetId()}).length &lt; <span class="number">1</span>
                removeLinks.push link.id

        <span class="keyword">for</span> linkId <span class="keyword">in</span> removeLinks
            <span class="property">@links</span>().remove(<span class="property">@links</span>().get linkId, {<span class="attribute">silent</span>: <span class="literal">true</span>})

        <span class="property">@save</span>()</pre></div>
        
      
        
        <h2 id="map-collection">MAP COLLECTION</h2>

        
      
        
        <p>Represents a collection of maps.</p>

        
          <div class='highlight'><pre><span class="class"><span class="keyword">class</span> <span class="title">SystemApp</span>.<span class="title">MapCollection</span> <span class="keyword">extends</span> <span class="title">SystemApp</span>.<span class="title">BaseCollection</span></span>
    <span class="attribute">typeName</span>: <span class="string">"MapCollection"</span>
    <span class="attribute">model</span>: SystemApp.Map
    <span class="attribute">url</span>: SystemApp.Settings.map.url</pre></div>
        
      
        
        <p>Set the comparator function to order the maps collection by name.</p>

        
          <div class='highlight'><pre>    <span class="attribute">comparator</span>: <span class="function"><span class="params">(map)</span> -&gt;</span> <span class="keyword">return</span> map.name()</pre></div>
        
      
      <div class="fleur">h</div>
    </div>
  </div>
</body>
</html>
